﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ATW.MT.BUS;
using System.Data;
using System.Text;
using System.Configuration;
using System.IO;

namespace ATW.MT.SellManage
{
    public partial class ProductionManage : System.Web.UI.Page
    {
        bus_T_production pro = new bus_T_production();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        private void BindData()
        {//数据绑定
            try
            {
                string proName = txtName.Value.Trim();
                if (!CommonClass.common.filterChar(proName))
                {
                    Tips("查询条件中存在危险字符！");
                    return;
                }
                DataTable dt = pro.ProductionPagerQuery(proName, "0", AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
                if (dt != null && dt.Rows.Count > 0)
                {
                    AspNetPager1.RecordCount = Convert.ToInt32(dt.Rows[0]["totalpagesize"]);
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        if (dt.Rows[i]["imgUrl"].ToString() != "")
                        {
                            dt.Rows[i]["imgUrl"] = ConfigurationManager.AppSettings["UploadFilePath"].ToString() + dt.Rows[i]["imgUrl"].ToString();
                        }
                    }
                }
                else
                {
                    AspNetPager1.RecordCount = 0;
                }
                rpList.DataSource = dt;
                rpList.DataBind();
            }
            catch (Exception ex)
            {

            }

        }
        protected void lbnDesc_Click(object sender, EventArgs e)
        {//描述页面
            LinkButton lbn = (LinkButton)sender;
            string productionID = lbn.CommandArgument;
            Label lblName = (Label)lbn.Parent.FindControl("lblName");
            string url = "../SellManage/ProductionDesc.aspx?pid=" + productionID + "&n=" + lblName.Text + "&r=" + new Random().Next(1000);
            OpenDialog("产品描述", url, "height=300,width=400");
        }
        protected void lbnArgs_Click(object sender, EventArgs e)
        {//参数管理页面
            LinkButton lbn = (LinkButton)sender;
            string productionID = lbn.CommandArgument;
            string url = "../SellManage/ProductionArgs.aspx?pid=" + productionID + "&r=" + new Random().Next(1000);
            OpenDialog("参数管理", url, "height=600,width=1000");
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {//查询
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }
        protected void AspNetPager1_pageChanged(object sender, EventArgs e)
        {//分页
            BindData();
        }
        private void Tips(string s)
        {//提示
            StringBuilder strScript = new StringBuilder();
            strScript.Append(@"<script language=javascript>
                var divTips=new jSharp.popUpDiv('divMsg');
                document.getElementById('msgContent').innerHTML='" + s + @"';
                divTips.Show();
                var t=setTimeout(function(){
                    divTips.Close();
                    clearTimeout(t);
                },1000);
            </script>");
            this.ClientScript.RegisterStartupScript(this.GetType(), "tips", strScript.ToString());
        }

        /// <summary>
        /// 打卡模态窗口
        /// </summary>
        /// <param name="name">窗口名称</param>
        /// <param name="url">窗口url</param>
        /// <param name="args">窗口宽和高，不需要加单位(height=xxx,width=xxx )</param>
        private void OpenDialog(string name, string url, string args)
        {
            StringBuilder strScript = new StringBuilder();
            strScript.AppendFormat(@"<script language=javascript>
                                        window.open('{0}','{1}','z-lock=yes,top=300,left=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,channelmode=yes,status=no,{2}')
                                    </script>", url, name, args);
            this.ClientScript.RegisterStartupScript(this.GetType(), "openDialog", strScript.ToString());
        }
    }
}